﻿@model dynamic
           
@{
    CmsPageControl item = Model.Model;
    ResFile = "cms_Pages";
    bool needRenderMoveUp = Model.RenderMoveUp;
    bool needRenderMoveDown = Model.RenderMoveDown;
    bool itemState = Model.IsMinState;
}

@functions{   
   string PageControlTitle(CmsPageControl control){
       
       if (!string.IsNullOrEmpty(control.AdminCaption))
       {
           return control.AdminCaption;
       }
       
       return control.CommonPageControlType == PageControlTypeKind.ModulePart ?
           control.Module.ModuleName :
           control.PageControlTypeDescription;
   }
   string PageControlTitleForDelete(CmsPageControl control)
   {
       return control.CommonPageControlType == PageControlTypeKind.ModulePart ?
           "section" :
           control.PageControlTypeDescription;
   }
   string GenerateId(){
       return Guid.NewGuid().ToString();
   }
   string MinOrMax(bool itemState, bool isHeader = true)
   {
       return itemState ?
           (isHeader ?
           "b-icon_expand_min" : "") :
           (isHeader ?
           "b-icon_expand_max" : "style=display:none");
   }
   string Move(bool itemState)
   {
       return !itemState ?
           "hide" :
           "";
   }
}

<div class="b-form b-form_bordered b-form_theme_white template-region template-region-@item.TemplateRegionId page-control-@item.Id">
    <div class="b-form__head b-form__head_grey js-control-head g-clear">
	    	    <h3 class="b-form__title">
                    <span class="js-control-title" title="@_("click to change caption")">@PageControlTitle(item)</span>
                    <span class="js-control-title-edit" style="display: none;">
                        <input type="text" name="@Html.GetClientNameForAdminViewElement(item.Id, "AdminCaption")" value="@PageControlTitle(item)"/>
                        <a class="js-control-title-save" href="#">@_("Ok")</a>
                    </span>
                    @if(ViewBag.Editable) {<a class="b-form__head__link b-entity-delete-pagecontrol hide" title="@item.PageControlTypeDescription" rel="@item.Id" href="@Url.Action("deletepagecontrol", "cmspage", new { pageId = item.PageId, templateRegionId = item.TemplateRegionId, pageControlId = item.Id })">@_("Delete section")</a>}</h3>
        @if(ViewBag.Editable)
        { 
            <a href="@Url.Action("moveup", "cmspagecontrol", new { pageControlId = item.Id })" rel="@item.PageId/@item.TemplateRegionId" class="b-icon b-icon_up page-control-move @Move(needRenderMoveUp)"></a>            
		    <a href="@Url.Action("movedown", "cmspagecontrol", new { pageControlId = item.Id })" rel="@item.PageId/@item.TemplateRegionId" class="b-icon b-icon_down page-control-move @Move(needRenderMoveDown)"></a>                        
        }
            <a id="@GenerateId()" href="#" class="b-icon b-icon_slider b-icon_expand @MinOrMax(itemState)"></a>
	</div>
	<div class="b-form__body g-clear page-control-body page-control-body-@item.Id" @MinOrMax(itemState, false)>
	 		@if (item.PageControlContentId.HasValue)
            {
                if (item.CommonPageControlType == PageControlTypeKind.Content)
                {
                    Html.RenderPartial("telerikeditor", new { ClientId = item.PageControlContentId.Value, Name = string.Format("PageControlContent_{0}", item.Id), Content = item.PageControlContent, ContentId = item.PageControlContentId.Value }.ToExpando());
                }
                else if (item.CommonPageControlType == PageControlTypeKind.Snippet)
                     {
                         <textarea class="text textarea textarea_snippet" rows="10" cols="20">@item.PageControlContent</textarea>
                         <br />
                         <a target="_blank" href="@Url.Action("edit", "cmscontent", new {id=item.PageControlContentId})">@_("Edit snippet")</a>
                         <div class="b-text-mask b-text-mask_snippet"></div>
                     }
                <input type="hidden" name="@string.Format("PageControlContentId_{0}", item.Id)" value="@item.PageControlContentId" />
            }
            else
            {
            @Html.PageControlEditor(item)
            }       
	</div>
</div>